// 声明全局 $request 类型
declare const $request: {
    get: (options: { url: string; params?: any }) => Promise<any>
    post: (options: { url: string; params?: any }) => Promise<any>
}

// 收购项目信息接口
export interface ProcurementItem {
    id: number
    merId: number
    gradeName: string
    sizeSpec: string
    productName?: string
    // 兼容不同接口字段命名
    price?: string
    purchasePrice?: string
    priceUnit?: string
    qualityRequirement?: string
    qualityRequirements?: string
    startDate?: string
    endDate?: string
    quoteDate?: string
    status: boolean
    isDel: boolean
    createTime: string
    updateTime: string
}

// 工厂收购信息接口
export interface FactoryProcurementInfo {
    id: number
    name: string
    businessHours: string
    procurementItems: ProcurementItem[]
    // 以下字段可能在其他接口中返回
    // UI展示所需的可选字段
    factoryName?: string
    province?: string
    city?: string
    district?: string
    addressDetail?: string
    mobilePhone?: string
    landlinePhone?: string
    procurementName?: string
    procurementCode?: string
    contactPerson?: string
    contactPhone?: string
    contactEmail?: string
    address?: string
    description?: string
    businessScope?: string
    registrationTime?: string
    status?: boolean
    sort?: number
    createTime?: string
    updateTime?: string
    coverImage?: string
    companyTypeTag?: string
    // 新增：报价有效期字段
    quoteValidStart?: string
    quoteValidEnd?: string
    quoteValidPeriod?: string
}

// 工厂收购列表响应接口
export interface FactoryProcurementListResponse {
    list: FactoryProcurementInfo[]
    total: number
    page: number
    limit: number
    totalPage: number
}

// 工厂价格明细查询参数
export interface FactoryProcurementPricesQuery {
    factoryId: number
    page: number
    limit: number
}

// 工厂价格明细响应
export interface FactoryProcurementPricesResponse {
    list: ProcurementItem[]
    total: number
    page: number
    limit: number
    totalPage: number
}

// API响应包装接口
export interface ApiResponse<T> {
    code: number
    message: string | null
    data: T
}

// 分页查询参数接口
export interface FactoryProcurementPageQuery {
    page: number
    limit: number
    keyword?: string
    status?: number
}

/**
 * 获取工厂收购分页列表
 * @param params 查询参数
 * @returns 工厂收购列表数据
 */
export const getFactoryProcurementListApi = (params: FactoryProcurementPageQuery) => {
    return $request.get({ url: 'front/factory/list', params })
}

/**
 * 获取工厂收购详情
 * @param id 工厂收购ID
 * @returns 工厂收购详情数据
 */
export const getFactoryProcurementDetailApi = (factoryId: number) => {
    return $request.get({ url: `/front/factory/info/${factoryId}` })
}

/**
 * 获取工厂价格明细（详情）
 * @param params { factoryId, page, limit }
 * @returns 价格明细分页数据
 */
export const getFactoryProcurementPricesApi = (params: FactoryProcurementPricesQuery) => {
    return $request.get<FactoryProcurementPricesResponse>({ url: 'front/factory/prices', params })
}
